package com.calvin.springcloud.feign.user.fallback;

import java.util.List;

import org.springframework.stereotype.Component;

import com.calvin.springcloud.base.ResponseResult;
import com.calvin.springcloud.feign.user.UserFei;
import com.calvin.springcloud.model.user.User;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class UserFeignFallbackFactory implements FallbackFactory<UserFei> {

	@Override
	public UserFei create(Throwable cause) {
		return new UserFei() {
			@Override
			public ResponseResult<List<User>> getUserList() {
				return null;
			}

			@Override
			public ResponseResult<User> findUser(Long userId, String userName) {
				cause.printStackTrace();
				log.error("[UserFeignFallbackFactory][findUser] reason was," + cause);
//				if (cause instanceof RuntimeException) {
//					return new ResponseResult<User>().fail("运行时异常," + cause.getMessage());
//				}
				return new ResponseResult<User>().fail("服务降级处理");
			}

			@Override
			public ResponseResult<Object> getUserListTimeOut() {
				return null;
			}
		};
	}

}
